Repository navigation
MENSA on Rotterdam (1/2): RotterdamDataset, MultiEventSurvivalRotterdam and MENSA (Lillelund et al., ML4H 2025) - #1644
Conversation
Test CoverageTotal: 87.13% (50562 / 58032 lines)
|
|
/review |
| """Penalty for predicting the later event before the earlier one. | ||
|
|
||
| Applies to patients who had both events. With ``variant="paper"`` | ||
| (Eq. 1 of the proposal), pass ``log S_later(t_earlier)``: the model |
There was a problem hiding this comment.
[low] Docstring cites 'the proposal' instead of the paper
The trajectory_nll docstring says the paper variant is 'Eq. 1 of the proposal'. The proposal is a private project document that readers of the library cannot see. Cite Eq. 1 of Lillelund et al. (ML4H 2025, PMLR 297) instead.
|
|
||
| @property | ||
| def label_processors(self) -> dict[str, LabelProcessor]: | ||
| """None: the model scores its survival outputs with its own loss. |
There was a problem hiding this comment.
[low] label_processors summary says None but the property returns {}
The first line of the docstring reads 'None: the model scores its survival outputs with its own loss', but the property returns an empty dict, and the Examples section shows {}. Reword the summary to say it returns an empty dict, as the example does.
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: approve
Thank you for this contribution. It adds a Rotterdam multi-event dataset, a recurrence/death task and a native PyTorch MENSA model, with clear docs and a careful comparison to the paper and the reference code. It looks ready to merge.
- Self-contained components: The new dataset, task and model build on BaseDataset, BaseTask and BaseModel without modifying them. The
__init__.pyedits only add exports. - Links between components: The task's reuse of
parse_rotterdam_recordis named in the description with a reason (row validation in one place). - Overlap with GBSGDataset: The description explains how it differs.
- Data source: The dataset cites the R survival package and the Royston and Altman paper.
- Coverage: It meets the bar. The whole repository is at 87.13%. The added files are at 100% (
rotterdam.py), 95.65% (mensa.py) and 100% (the task).
Optional suggestions:
- In the
trajectory_nlldocstring, "Eq. 1 of the proposal" should read "Eq. 1 of the paper". - The
label_processorsdocstring summary says "None", but the property returns{}. Aligning the two would be clearer.
Reviewed commit 80cf63e
Part 1 of 2 of #1642. #1642 was too large for AI review (251k diff characters, mostly the example script), so the dataset, task and model are split out here. The example and the experiments stay in #1642. After this PR merges, #1642 will be rebased so it shows only the example.
Contributor: Zhenshuo Xu (NetID: zx65)
Contribution type: Dataset + Task + Model (part 1 of the full pipeline contribution #1642; CS 598 DL4H Option 4, reproducibility)
Paper: Lillelund et al., "MENSA: A Multi-Event Network for Survival Analysis with Trajectory-based Likelihood Estimation", ML4H 2025 (PMLR 297).
Links: PMLR | arXiv | Reference code
Description
This PR adds multi-event survival analysis on the Rotterdam breast cancer cohort:
RotterdamDatasetloads the full 2,982-patient cohort (10 baseline features, with separate time and indicator columns for recurrence and death) from a localrotterdam.csv. It validates the full CSV before caching and does not download anything.MultiEventSurvivalRotterdambuilds one sample per patient (features,event_times,event_indicators) with event times kept in raw days. Settinguse_treatment=Falsedrops the two treatment indicators (8 features instead of 10).MENSAis a native PyTorch implementation of the paper's model. A shared backbone outputs a Weibull mixture for each event, and the trajectory loss penalizes predicting death before recurrence for patients who experienced both.fit_preprocessing(train)fits feature scaling and loss weights on the training split only, andpredict_survivalevaluates survival curves on any time grid.Data: The cohort is public in R's
survivalpackage (survival::rotterdam). Downloaddata/rotterdam.csvfrom the authors' repository, or export it from R withwrite.csv(survival::rotterdam, "rotterdam.csv", row.names = FALSE). Then put the file in therootdirectory passed to the dataset.Relation to existing code
PyHealth already has
GBSGDataset, which loads DeepSurv's pooled Rotterdam/GBSG benchmark (2,232 records, 7 features, single recurrence-free survival endpoint).RotterdamDatasetinstead keeps the full 2,982-patient Rotterdam cohort with recurrence and death modeled as separate events.The task reuses
parse_rotterdam_recordfrompyhealth/datasets/rotterdam.pyso row validation lives in one place. Outside the new files, the only edits to existing code are three__init__.pyexports and three docs index entries (no changes to PyHealth core).Differences from the reference code
The model was reimplemented natively in PyTorch, adapted from
thecml/mensa(MIT License, commit6b219cd), with no imports from that repository. A few intentional differences:trajectory_variant="reference"switches to the code's version.1e-3, while the reference Rotterdam config uses 16, 0.5, and1e-4.0, for every split. Here the model seed matches the split seed.Trainerrestores an actual copy.The reproduction results (E1-E4) are in #1642.
Tests
52 unit tests across three files in
tests/core/, all using small synthetic data (the suite runs in about 1 second):Files to review
pyhealth/datasets/rotterdam.py,pyhealth/datasets/configs/rotterdam.yamlpyhealth/tasks/multi_event_survival_rotterdam.pypyhealth/models/mensa.pypyhealth/datasets/__init__.py,pyhealth/tasks/__init__.py,pyhealth/models/__init__.py(exports only)docs/api/datasets/pyhealth.datasets.RotterdamDataset.rst,docs/api/tasks/pyhealth.tasks.multi_event_survival_rotterdam.rst,docs/api/models/pyhealth.models.MENSA.rst, and index entries indatasets.rst,tasks.rst,models.rsttests/core/test_rotterdam.py,tests/core/test_multi_event_survival_rotterdam.py,tests/core/test_mensa.py